<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/h5tablecss.css">
</head>

<body>
<form>
    <h1>学生列表</h1>
    <table class="responsive">
        <br />

        <br />
        <thead>

        <tr>
            <td colspan="8"><input type="button" id="addButton" value="新增学生" style="float: right"></input></td>
        </tr>
        <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>出生日期</th>
            <th>手机号</th>
            <th>班级</th>
            <th>学院</th>
            <th>操作</th>
        </tr>
        </thead>
        <tr th:each="all:${all}">
            <td th:text="${all.sNum}"></td>
            <td th:text="${all.sName}"></td>
            <td th:text="${all.gender}"></td>
            <td th:text="${#dates.format(all.birthday,'yyyy-MM-dd')}"></td>
            <td th:text="${all.phone}"></td>
            <td th:text="${all.classTable.cName}"></td>
            <td th:text="${all.institutes.iName}"></td>
            <td>
                <input th:class="delButton"  type="button" value="删除">
                <input th:class="updButton" type="button" value="修改">
            </td>
        </tr>

        </tr>
        <tr>
            <td colspan="8">
                <br>
                当前第<span th:text="${page.pageNum}"></span>页
                <br>
                <button><a th:href="@{/findAll(pageNum=1)}">首页</a></button>
                <button><a th:href="@{/findAll(pageNum=${page.hasPreviousPage}?${page.prePage}:1)}">上一页</a></button>
                <button><a th:href="@{/findAll(pageNum=${page.hasNextPage}?${page.nextPage}:${page.pages})}">下一页</a></button>
                <button><a th:href="@{/findAll(pageNum=${page.pages})}">尾页</a></button>
            </td>
        </tr>
    </table>
</form>
</body>
<script src="webjars/jquery/2.1.0/jquery.min.js"></script>
<script>

   $(function (){

       $(".delButton").click(function (){
           var a = $(this);
           var sNum = $(this).parent().prevAll().eq(6).text();
           $.get("/delStudent",{"sNum":sNum},function (data){
               if (data == "Success"){
                   a.parent().parent().remove();
               }
           });
       })


       $(".updButton").click(function (){
           var a = $(this);
           var sNum = $(this).parent().prevAll().eq(6).text();
           window.location.href="/toStudentUpd?sNum=" + sNum;
       })


       $("#addButton").click(function (){
           window.location.href="/toAdd";
       })

   })

</script>
</html>